Skip to main content
Version: 4.2

Overview

ScriptUtil is packed APIs that you can use to design the interactions between elements through scripts in application design.

Basic Rules

  • The namespace of form templates created under an application is the current application namespace. Its format is developer_app name. Namespace of form templates created on the supOS system is system.
    tip

    You can check the namespace of object templates on their basic information page, and properties on the property list.

  • When using scriptUtil APIs, with repeated alias, we recommend adding namespace to differentiate them from each other during calling. Otherwise, objects with same aliases will be called at the order of starting from the application, to supOS platform and to other applications.
  • When using scriptUtil APIs (callFunction excluded) on supOS V2.80.01.02 and later versions, add a parameter version: 'V2'. Older versions like V2.70.01.00 uses version: 'V1' (embedded).
  • When using scriptUtil APIs that are related to form templates (add, delete, insert and search) supOS V2.80.01.02 and later versions, we recommend using callFunction instead to unify service calling.

API Description

Service Execution

executeSrciptService

Usage
Call embedded services of object templates or custom services.
Parameter
  • objName: Required. Locate the corresponding template or instance.
  • serviceName: Required. Service name that you want to call.
  • params: Optional. Input parameters of the service.
  • cb[callback]: Callback function.
  • version: Version number. Mostly for differentiating V2.7 and V3.0.
Example
// call service under a form template
var objName = 'namespace.templateName';
// call service under an instance of an entity template
var objName = 'namespace.templateName/instanceName';
scriptUtil.executeScriptService({
objName, // template or instance
serviceName:"namespace.querySQLExec", // service namespace and service alias
// input parameters of service
params:{ },
version: 'V2',
// callback function
cb:function(res){
console.log('res', res);
}
// custom request parameters
});

getRequestUrl

Usage
Get the string after ? in a URL link and return it as an object.
Example
// url is https://www.baidu.com?id=123&code=456
var data = scriptUtil.getRequestUrl();
console.log(data)
// return data
{
id: 123,
code: 456
}

getTimeZone

Usage
Get current timezone and return it as an object.
Example
var Offset = scriptUtil.getTimeZone();
console.log(Offset)

reload

Usage
Refresh current page after the set delay.
Parameter
(number) refers to the delay time with millisecond as unit.
Example
// refresh the page in 50 ms
scriptUtil.reload(50);

refreshWorkflow

Usage
Refresh workflow.
Example
var Offset = scriptUtil.refreshWorkflow();

copy

Usage
Copy data to clipboard.
Parameter
  • (any) refers to the data to be copied.
Example
scriptUtil.copy(any);

request

Usage
Call third-party service or openAPI interface of supOS.
Parameter
  • (string): Refers to the request url.
  • (object): Refers to input parameters.
    • method: Request method such as POST/GET/DELETE/PUT.
    • body: Input parameters.
Example
var url = '/api/openapi/notification/v1/message';
var param = {
method: 'POST', //request method such as GET, POST, PUT and DELETE
body: {}, //optional
headers: {} //optional
};
scriptUtil.request(url, param).then(res=>{
console.log(res)
});

scriptUtilReact Component

registerReactDom

Usage
Register as a ReactDom in Programmable Component, and then can be called by using the component in business designer.
Parameter
  • (component): Component instance.
  • (object): Props.
Example
scriptUtil.registerReactDom(this, this.props);

logoutReactDom

Usage
Logout the registered ReactDom instance in Programmable Component, and often can be called in the lifecycle of componentWillUnmount to release storage.
Parameter
  • (component): Component instance.
  • (object): Props.
Example
scriptUtil.logoutReactDom(this, this.props);

getRegisterReactDom

Usage
Get registered component instance to call the embedded functions.
Parameter
(string): Refers to component ID and returns the registered component instance.
Example
var reactInstance = scriptUtil.getRegisterReactDom('htdiv-xxxx');
reactInstance.getValue()

getFormData

Usage
Get component value to obtain form data after submitted.
Parameter
(array): Refers to component name and returns corresponding component value as an object.
Example
scriptUtil.getFormData(['title', 'name', 'age']);

setFormData

Usage
Set component value to fill in the form and change form data.
Parameter
(object): Component name: Component value.
Example
scriptUtil.setFormData({ title: 'test data' });

submitDefaultValue

Usage
Bind form component to trigger data search.
Parameter
  • (component): Form component instance.
  • (string): To-be-set values of form component instance.
  • (string): Tag. 1 means automatically submit the form and 0 means manual submit.
    info

    Automatic submit is only valid when setting Linkage to Automatic in Page Configuration in free layout.

Example
const component = scriptUtil.getRegisterReactDom('ctrlId');
scriptUtil.submitDefaultValue(component, 'search value', '1');

General Tool of scriptUtil

Alert

Usage
pop-up window.
Parameter
  • (string): Message.
  • (function): Callback
    info

    Callback is only triggered when clicking ok on the pop-up window.

Example
scriptUtil.Alert('Prompted Successfully', () => {
console.log('Click OK');
});

showMessage

Usage
Display a message.
Parameter
  • (string): Message.
  • (string): Message type, including success/warning/info/error.
Example
scriptUtil.showMessage('Message', 'success');

timestampFormat

Usage
Formats timestamp and returns time string with the set formatting.
Parameter
  • (number): Timestamp.
  • (string): Time format.
Example
scriptUtil.timestampFormat(1587109353040, 'YYYY-MM-DD HH:mm:ss');
// "2020-04-17 15:42:33"

timestampAntiFormat

Usage
Deformats time strings and returns corresponding timestamp.
Parameter
(string): General time string.
Example
scriptUtil.timestampAntiFormat('2021-05-01 01:00:00');
// 1619802000000

regRexGroup

Usage
Checks whether the corresponding variable matches the regular expressions and returns it.
Parameter
(string): Regular expression type, including mobilePhone/telephone/zipCode/idCard/number/email/ip.
Example
const reg = scriptUtil.regRexGroup('mobilePhone');
const variable_1 = '18866668888';
const variable_3 = '1886666777';
reg.test(variable_1); //true;
reg.test(variable_3); //false;

isVaild

Usage
Checks whether the component value formatting conforms to the set rules when submitting the form and returns the result as true or false.
Parameter
(array): Component IDs.
Example
scriptUtil.isVaild(['ctrlId1', 'ctrlId2', 'ctrlId3']);

getFormatterMap

Usage
Get component title and name according to its ID and return an object.
Parameter
(array): Component IDs.
Example
scriptUtil.getFormatterMap(['ctrlId1', 'ctrlId2', 'ctrlId3']);

parseTableMap

Usage
Replace object keys inside an array and return a new array.
Parameter
  • (array): Data source.
  • (object): Map.
  • (string): Index.
Example
// parseTableMap(data, map, index = 'number')
const data = [{name:'Emma',age: 123},{name:'Judy',age: 33}];
const map = {name: 'name',age: 'age'}
const result = scriptUtil.parseTableMap(data,map, 'number')
console.log(result)
[
{
"number": 1,
"name": "Emma",
"age": 123
},
{
"number": 2,
"name": "Judy",
"age": 33
}
]

objKeySort

Usage
Sort the object keys and return a new object.
Parameter
  • (object): Data source.
  • (array): Field array that needs to be sorted.
Example
const data = {name:'Emma',age: 123, sex: 'F'}
const sort = ['sex', 'age', 'name']
const result = scriptUtil.objKeySort(data,sort)
console.log(result)
{
sex: 'F'
age: 123,
name:'Emma',
}

getEditRow

Usage
Get data of the clicked table row and return an object.
Parameter
(string): Table component ID.
Example
var result = scriptUtil.getEditRow('table component id')

JSONToExcelConvertor

Usage
Export data to excel tables.
Parameter
  • (array): Data source.
  • (array): Data title.
  • (array): Data key, corresponding to data title.
  • (string): Exported file name.
  • (string): Exported file extension, including csv/xls.
Example
scriptUtil.JSONToExcelConvertor({
data: [{ name: 'Emma', age: '12', sex: 'F' }],
dataTitle: ['name', 'age', 'sex'],
dataKey: ['name', 'age', 'sex'],
fileName: 'test file',
extension: 'xls',
});

scriptUtil Page Operation

closeCurrentPage

Usage
Close current page.
Example
scriptUtil.closeCurrentPage();

openPage

Usage
Open a new page or search for a named page.
Parameter
  • (string): Url of the target page and if no targets, open a new page.
  • (string): Name of target property or page. You can select from blank (new page)/parent (parent page)/self (replace current page)/top (any locadable page)/name (page name)
  • (array): Data key, corresponding to data title.
  • (boolean): Feature. Whether or not support customization.
  • (string): openConfig[JSON]. Page configruation.
Example
// blank page
scriptUtil.openPage('url', '_blank');

// replace current page
scriptUtil.openPage('url', '_self');

// empty page with set size
scriptUtil.openPage('url', '_blank', true, '{"height":400,"width":400}');

showModal

Usage
Open a new modal window.
Parameter
(string) refers to pop-up window configuration. You can select from modalVisible/modalWidth/modalHeight/modalTitle.
Example
scriptUtil.showModal(`{
"width":800,
"height":600,
"padding":{"paddingTop":24,"paddingBottom":24,"paddingLeft":24,"paddingRight":24},
"modelTitle":"title",
"needTitle":true,
"fontSize":14,
"fontColor":"#000000",
"titleBgColor":"#ebeef5",
"contentBgColor":"#ffffff",
"modalIsCenter":true,
"url":"/#/runtime-fullscreen/runtime-fullscreen/Page_401bf68ecd634809a7cf36fe44b73f59",
"sandbox":"allow-forms allow-same-origin allow-scripts allow-popups allow-downloads",
"isSandbox":true
}`)

closeModal

Usage
Close modal window.
Example
scriptUtil.closeModal();

closeParentModal

Usage
Close modal window of parent page.
Example
window.parent.scriptUtil.closeModal();

scriptUtil Database Operation

addDataTable

Usage
Add data to data table.
Parameter
  • dataSource: Table name.
  • properties: Specific data to be added to the database.
  • version: Version number.
  • function: Callback parameter. Only accept one result parameter.
Example
const param = {
'namespace.p1': 'p1',
'namespace.p2': 'p2',
};
scriptUtil.addDataTable(
{
dataSource: 'namespace.tableName',
properties: [param], //must be array type
version: 'V2',
},
function (res) {
console.log('res', res);
}
);

delDataTable

Usage
Delete data from data table.
Parameter
  • dataSource: Table name.
  • properties: Specific data to be deleted from the database. ID needs to be specified.
  • version: Version number.
  • function: Callback parameter. Only accept one result parameter.
Example
const param = {
id: 'xxx', //can only delete data based on id.
};
scriptUtil.delDataTable(
{
dataSource: 'namespace.tableName',
properties: [param], //must be array type
version: 'V2',
},
function (res) {
console.log('res', res);
}
);

updateDataTable

Usage
Update data to data table.
Parameter
  • dataSource: Table name.
  • properties: Specific data to be updated to the database.
  • keys: Object. Similar to where conditions.
  • version: Version number.
  • function: Callback parameter. Only accept one result parameter.
Example
//Update condition: code is 1623219467408
//Update result: comDetailAdd is Ningbo, Zhejiang Province
var dataSource = 'supyoung_companyreg.company_reg';
var param = {
comDetailAdd: 'Ningbo, Zhejiang Province', //field to be updated
};
var keys = {
'supyoung_companyreg.code': '1623219467408',//key must appear with namespace
};
scriptUtil.updateDataTable(
{
dataSource,
properties: [param], // must be array type
keys,
version: 'V2',
},
function (res) {
console.log('res', res);
}
);

queryDataTable

Usage
Search for data from data table.
Parameter
  • dataSource: Table name.
  • filters: Object.
    • fields: Array. Optional. Column array and ; is used to separate multiple columns. When fields are empty, all columns are returned.
    • order: Optional. Sorting order.
    • distinct: Optional. Whether to deduplicate data. It is false when no input parameters by default and only valid when fields is not empty.
    • pageIndex: optional. Start page of the query. It is 1 by default.
    • pageSize: Optional. Page size of the query. It is 50 by default.
    • Custom search conditions: Optional. Union set. ’%xxx%’ represents fuzzy matching.
  • version: Version number.
  • function: Callback parameter. Only accept one result parameter.
Example
//Update condition: code is 1623219467408
//Update result: comDetailAdd is Ningbo, Zhejiang Province
var namespace = "supyoung_companyreg"
var dataSource = namespace+'.company_reg';
scriptUtil.queryDataTable(
{
dataSource,
filters: {
fields:['desc'],//search for specified field
order: [
{
"order": "code",//field to be sorted
"sort": "desc" //desc -descending order asc-ascending order
}
],
distinct: true,
pageIndex: 1,
pageSize: 5,
"supyoung_companyreg.company":"%xx%",//search for company named xx (namespace is required)
},
version: 'V2'
},
function(res) {
console.log('res', res);
}
);

callFunction

Usage
Call services under object template or instance.
Parameter
  • path: Required. Service path, which can be template alias/template namespace.template alias for service under object template and template alias/instance alias or template namespace.template alias/instance alias for service under object instance.
  • service: Required. Service alias or service namespace.service alias.
  • params: Optional. Input parameters of the service.
Example
  • Calling service under object template
    scriptUtil.callFunction('templateNamespace.templateName', 'callService', {a: 1});
  • Calling service under object instance
    scriptUtil.callFunction('templateNamespace.templateName/instanceName', 'callService', {a: 1})
    .then(function(res){
    console.log('then:res');
    });

scriptUtil User Information

getUserInfo

Usage
Get user information.
Parameter
(function) refers to callback function.
Example
scriptUtil.getUserInfo(function (res) {
// res is current user information
console.log('res', res);
});

getSessionUserInfo

Usage
Get user session information from sessionStorage and return an object.
Example
scriptUtil.getSessionUserInfo();

setAuthority

Usage
Logout.
Example
scriptUtil.setAuthority();